﻿@*YoursLC有源低代码 Create:admin 2023-07-04 14:31:24 弹出选择从自定义录入表取值-此文件放置于Views/GoodsOutbound /中*@

@using Think9.Models;
@{ ViewBag.Title = "Index";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<input style="display:none" id="_fromfw" value="bi_ProductManagement">@*取值数据表的流程id,查看详细时需要,为空则不会触发*@
<input style="display:none" id="_flag" value="OutboundDetailsv1">@*父页面的指标id*@
<input style="display:none" id="pu_frm" value="@ViewBag.PuFrom">@*list或者add*@
<input style="display:none" id="pu_tbid" value="@ViewBag.PuTbId">@*表id*@
<input style="display:none" id="pu_indexid" value="@ViewBag.PuIndexId">@*指标编码*@
<input style="display:none" id="pu_rowid" value="@ViewBag.PuId">@*子表弹出时使用 对应tableid 哪一行*@
<input style="display:none" id="pu_column" value="@ViewBag.PuV">@*子表弹出时使用 第几列*@
<fieldset class="table-fieldset" id="searchfield" style="display:none">
	<legend style="color:darkgrey">快速查询</legend>
	<div style="margin: 5px 5px 5px 5px">
		<form class="layui-form layui-form-pane" action="">
			<div class="layui-row layui-col-space10">
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">货品名称</label>
					<div class="layui-input-block">
						<input type='text' name="inHPMC" id="inHPMC" autocomplete='off' class='layui-input'>
					</div>
				</div>
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">所属类别</label>
					<div class="layui-input-block">
						<select id="inSSLB" name="inSSLB">
							<option value="">==请选择==</option>
								@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inSSLB"))
								{
									 <option value="@item.Value">@item.Text</option>
								}
						</select>
					</div>
				</div>
			 </div>
			<div class="layui-row layui-col-space10">
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">计量单位</label>
					<div class="layui-input-block">
						<select id="inJLDW" name="inJLDW">
							<option value="">==请选择==</option>
								@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inJLDW"))
								{
									 <option value="@item.Value">@item.Text</option>
								}
						</select>
					</div>
				</div>
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">最低库存</label>
					<div class="layui-input-inline">
						<div class="layui-input-inline" style="width: 90px; ">
							<input type='text' name="inZDKC" id="inZDKC" autocomplete='off' class='layui-input'  lay-verify='number' >
						</div>
						<div class="layui-input-inline" style="width: 5px; ">-</div>
						<div class="layui-input-inline" style="width: 90px; ">
							<input type='text' name="inZDKC_Exa" id="inZDKC_Exa" autocomplete='off' class='layui-input'  lay-verify='number' >
						</div>
					</div>
				</div>
			 </div>
			<div class="layui-row layui-col-space10">
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">最高库存</label>
					<div class="layui-input-inline">
						<div class="layui-input-inline" style="width: 90px; ">
							<input type='text' name="inZGKC" id="inZGKC" autocomplete='off' class='layui-input'  lay-verify='number' >
						</div>
						<div class="layui-input-inline" style="width: 5px; ">-</div>
						<div class="layui-input-inline" style="width: 90px; ">
							<input type='text' name="inZGKC_Exa" id="inZGKC_Exa" autocomplete='off' class='layui-input'  lay-verify='number' >
						</div>
					</div>
				</div>
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<label class="layui-form-label">启用|停用</label>
					<div class="layui-input-block">
						<select id="inQYTY" name="inQYTY">
							<option value="">==请选择==</option>
								@foreach (valueTextEntity item in ((IEnumerable<valueTextEntity>)ViewBag.SelectList).Where(x => x.ClassID == "inQYTY"))
								{
									 <option value="@item.Value">@item.Text</option>
								}
						</select>
					</div>
				</div>
			 </div>
			<div class="layui-row layui-col-space10">
				<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<button type='button' class='layui-btn' id='search' lay-submit lay-filter='search' lay-tips='查询'><i class='layui-icon layui-icon-search'></i></button> <button type='reset' class='layui-btn layui-btn-primary' lay-tips='清空'><i class='layui-icon layui-icon-refresh'></i></button>
				</div>
			 </div>
		</form>
	</div>
</fieldset>

<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script>
	layui.config({
		base: '/self_js/' /*自定义的js文件 wwwroot/self_js文件夹中*/
	});
	layui.use(["table", "form", "exLayer", "exUtils", "GoodsOutbound"], function () {
		let table = layui.table;
		let form = layui.form;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let myJS = layui.GoodsOutbound;

		let $ = layui.$;

		form.render(); //

		let ThisTable = table.render({
			elem: "#tableId",
			url: "/_TB/GetPopUpPageList?indexid=" + $('#_flag').val() + "&from=" + $('#pu_frm').val() + "&fwid=" + $(window.parent.document).find('#_fwid').val(),
			limits: [10, 50, 100],
			limit: 10,
			method:"POST",
			page: true,
			defaultToolbar: [{ title: '搜索', layEvent: 'searchShow', icon: 'layui-bg-blue layui-icon-search' }, 'filter' ],
			toolbar: "#toolbarTpl",
			cols: [[
			{ type: "radio", fixed: 'left' }

			   ,{ type: "numbers", title: "NO.", fixed: 'left' }
			   ,{ field: "Value", hide: true  }
			   ,{ title: "详细", width: 60,  templet: "#operation_Tpl" }
				,{ field: "info1", title: "货品编码", width: layui.device().mobile ? 120 : null }
				,{ field: "info2", title: "货品名称", width: layui.device().mobile ? 120 : null }
				,{ field: "info3", title: "规格型号", width: layui.device().mobile ? 120 : null }
				,{ title: "货品图片",templet: '#T_info4', width: layui.device().mobile ? 120 : null }
				,{ field: "info5", title: "销售价", width: layui.device().mobile ? 120 : null }
				,{ field: "info6", title: "成本价", width: layui.device().mobile ? 120 : null }
			]],
			done: function (res, curr, count) {
                if (count == -1) {
                    layer.msg(res.msg, { icon: 5, time: 20000, btn: ['关闭'] });//显示错误
                }
			}
		});

		 //查询
		form.on("submit(search)", function (data) {
			$("#searchfield").hide();
			var _list = [];
			getControlSearch(_list);
			console.log(_list);

			ThisTable.reload({
				where: { flag: $('#_flag').val(), "list": _list, fwid: $(window.parent.document).find('#_fwid').val() },
				page: { curr: 1 }
			});
			return false;
		});

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "OK":
                    getPopUpSelect(obj);
                    break;
                case "searchShow":
                    myJS.searchShow();
                    break;
            }
        });

		//数据表格自带的监听radio事件
        table.on('radio(tableFilter)', function (obj) {
            document.body.scrollTop = document.documentElement.scrollTop = 0;
        });

		function getPopUpSelect(obj) {
			var strv = '';
			var checkStatus = table.checkStatus(obj.config.id);
			if (checkStatus.data.length > 0) {
				strv = checkStatus.data[0].Value;
			}


            //调用后台处理函数 默认什么也不做--可自定义
            exUtils.ajax('/_TB/AfterPopUpSelect', 'post', {
                tbid: $('#pu_tbid').val(), indexid: $('#pu_indexid').val(), id: $('#pu_rowid').val(), value: strv, v: $('#pu_column').val()
            }, true).done(function (response) {
            }).fail(function (error) {
                console.log(error);
            });

            //为父页面控件赋值
			$(window.parent.document).find('#pu_value').val(strv);//选择的值
			$(window.parent.document).find('#pu_tbid').val($('#pu_tbid').val());//表id
			$(window.parent.document).find('#pu_indexid').val($('#pu_indexid').val());//指标编码
			$(window.parent.document).find('#pu_rowid').val($('#pu_rowid').val());//对应table中id可确定行
			$(window.parent.document).find('#pu_column').val($('#pu_column').val());//第几列

			$(window.parent.document).find('#pu_value').click();//调用父页面事件，完成控件赋值及数据读取

			parent.layer.close(parent.layer.getFrameIndex(window.name));
		}

		//从控件读值，将查询条件push传给后端
		function getControlSearch(_list) {
			//货品名称
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inHPMC').val(), Value:'inHPMC'});
			//所属类别
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inSSLB').val(), Value:'inSSLB'});
			//计量单位
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inJLDW').val(), Value:'inJLDW'});
			//最低库存
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inZDKC').val(), Value:'inZDKC'});
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inZDKC_Exa').val(), Value:'inZDKC_Exa'});
			//最高库存
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inZGKC').val(), Value:'inZGKC'});
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inZGKC_Exa').val(), Value:'inZGKC_Exa'});
			//启用|停用
			_list.push({ ClassID: $('#_flag').val(), Text:$('#inQYTY').val(), Value:'inQYTY'});
		}

	});
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="OK" id="OK">确定选择</button>
	<span class="layui-word-aux"><i class="fa fa-angle-double-left"></i>选择后，需点击【确定】按钮</span>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operation_Tpl">
    <a href="/Com/RDLCReport/ExportHtml?listid={{d.Id}}&fwid=bi_ProductManagement" target="_blank" id="print" class="layui-btn layui-btn-primary layui-btn-xs">
        <i class='fa fa-file-text-o'></i>
    </a>
</script>
<script type="text/html" id="T_info4">
{{#  if(d.info4 != null){ }}<div><i class='fa fa-picture-o'></i><span onclick="PopUpImg('{{d.info4}}')">{{d.info4}}</span></div>{{#  } else{ }} {{#  } }}
</script>

<!-- 图片显示 -->
<script>
    function PopUpImg(id) {
        showImg(id);
    }
</script>